package com.example.dllo.exe.me;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.dllo.exe.R;
import com.example.dllo.exe.fengzhuang.DBTool;
import com.example.dllo.exe.giftspeak.songnvpiao.SongNvPiaoSecondTopAty;
import com.example.dllo.exe.main.BaseFragment;
import com.example.dllo.exe.bean.SQLGongLueBean;

import java.util.ArrayList;

/**
 * code is far away from bug with the animal protecting
 * <p>
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃永无BUG！  凯哥 祝你一路顺风
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 */
public class MeGonglueFragment extends BaseFragment {
    private ListView listView;
    private MeGongLueAdapter meGongLueAdapter;



    @Override
    protected int setLayout() {
        return R.layout.megonglueframentlayout;
    }

    @Override
    protected void initView() {
        listView = bindView(R.id.lv_me);

    }

    @Override
    protected void initData() {


        meGongLueAdapter = new MeGongLueAdapter(getContext());
        listView.setAdapter(meGongLueAdapter);
        DBTool.getInstance().queryAllStudent(new DBTool.QueryListener() {
            @Override
            public void onQueryComplete(ArrayList<SQLGongLueBean> sqlGongLueBeen) {
                meGongLueAdapter.setSqlGongLueBean(sqlGongLueBeen);
            }
        });
        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {

                DBTool.getInstance().deleteStudent(meGongLueAdapter.getItem(i).getTitle());
                meGongLueAdapter.deletePos(i);
                return true;

            }
        });
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            private Intent intent;

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                Intent intent1=new Intent(getContext(), SongNvPiaoSecondTopAty.class);
                intent = getActivity().getIntent();
                intent.getStringExtra("key");
                startActivity(intent1);




            }
        });




//        BmobQuery<Collection> bmobQuery = new BmobQuery<Collection>();
//        bmobQuery.getObject("1e2f16fb14", new QueryListener<Collection>() {
//            @Override
//            public void done(Collection collection, BmobException e) {
//                if (e == null) {
//                    Log.d("MeGonglueFragment", "查询成功");
//
//                    Picasso.with(getContext()).load(collection.getUrl()).fit().into(imageViewphoto);
//
//
//                    textViewtitle.setText(collection.getTitle());
//                    textViewname.setText(collection.getName());
//                } else {
//                    Log.d("MeGonglueFragment", "查询失败");
//                }
//            }
//        });


    }

}

